
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import javax.swing.JPanel;
import javax.swing.Timer;


public class StartWindow extends JPanel implements ActionListener {
	
	private Timer timer;
	private Spielstein spielstein;
	
	public StartWindow() {
		
		addKeyListener(new TAdapter());
		setFocusable(true);
		setBackground(Color.LIGHT_GRAY);
		setDoubleBuffered(true);
		spielstein = new Spielstein();
		timer = new Timer(200, this);
		timer.start();
	}
	
	public void paint(Graphics g) {
		super.paint(g);		
		Graphics2D graphic = (Graphics2D) g;
		graphic.drawImage(spielstein.getImage(), spielstein.getX(), spielstein.getY(), this);
		Toolkit.getDefaultToolkit().sync();
		g.dispose();
	}
	
	public void actionPerformed(ActionEvent e) {
		spielstein.move();
		repaint();
	}
	
	private class TAdapter extends KeyAdapter {

        public void keyReleased(KeyEvent e) {
            spielstein.keyReleased(e);
        }

        public void keyPressed(KeyEvent e) {
            spielstein.keyPressed(e);
        }
    }
	
	
}
